<script setup lang="ts">
import type {SelectOption} from '~/types/layui/select'
import type {JobLog} from '~/types/log/jobLog'

defineProps<{
  /** 状态下拉框数据 */
  statusOptions: SelectOption[]
}>()

const emit = defineEmits<{
  (e: 'onSearch', formModel: JobLog): void
}>()

const searchFormRef = ref()
const formModel = reactive<JobLog>({
  createTime: '',
  status: undefined,
  classPath: '',
  jobHandlerName: '',
})
defineExpose({ formModel })

/** 表单搜索事件 */
function search() {
  return emit('onSearch', formModel)
}

/** 表单重置事件 */
function reset() {
  return searchFormRef.value.reset()
}
</script>

<template>
  <div class="z-search-layout">
    <lay-row space="8">
      <lay-col :md="22" :sm="20" :xs="24">
        <lay-form
          ref="searchFormRef"
          :model="formModel"
        >
          <lay-row>
            <lay-col :md="8" :sm="12" :xs="24">
              <lay-form-item label="任务状态" prop="state">
                <lay-select v-model="formModel.status" placeholder="请选择" allow-clear style="width: 100%">
                  <template v-for="status in statusOptions" :key="status.value">
                    <lay-select-option :value="status.value" :label="status.label" />
                  </template>
                </lay-select>
              </lay-form-item>
            </lay-col>
            <lay-col :md="8" :sm="12" :xs="24">
              <lay-form-item label="类路径" prop="account">
                <lay-input v-model="formModel.classPath" placeholder="请填写" allow-clear />
              </lay-form-item>
            </lay-col>
          </lay-row>
          <lay-row>
            <lay-col :md="8" :sm="12" :xs="24">
              <lay-form-item label="任务处理器名称" label-width="120" prop="os">
                <lay-input v-model="formModel.jobHandlerName" placeholder="请填写" allow-clear />
              </lay-form-item>
            </lay-col>
          </lay-row>
        </lay-form>
      </lay-col>
      <lay-col :md="2" :sm="4" :xs="24" class="z-text-center">
        <lay-space :direction="isXs ? 'horizontal' : 'vertical'" wrap>
          <lay-button type="primary" @click="search">
            <lay-icon type="layui-icon-search" /> 查询
          </lay-button>
          <lay-button @click="reset">
            <lay-icon type="layui-icon-refresh-three" /> 重置
          </lay-button>
        </lay-space>
      </lay-col>
    </lay-row>
  </div>
</template>

<style scoped>
:deep(.layui-form-item) {
  margin-bottom: 10px;
}
</style>
